from sklearn import svm

from ENF_deepLearning.utils.parent.Base import Base
import numpy as np

class SVM_Classifier(Base):
    def svm(self, x_train, x_test, y_train, y_test):
        print('#############             SVM开始预测             #############')
        svm_model = svm.SVC(kernel='poly')
        svm_model.fit(x_train, y_train)
        res = svm_model.predict(x_test)
        a = np.sum(res == y_test)
        print(res, y_test) # 0.8是结果
        print("ans = ",a / y_test.shape[0])

        self.save_pred_true(res.tolist(), y_test.tolist())
        # print(self.y_pred)
        # draw_confusion_matrix(y_test, res, [0, 1, 2, 3, 4, 5, 6, 7], 'confusion matrix of SVM')